package vboot.app.module.sa.cust.main;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vboot.app.module.sa.agent.main.SaAgentMain;
import vboot.app.module.sa.agent.main.SaAgentMainRepo;
import vboot.core.xutil.lang.XstrUtil;

import javax.annotation.Resource;


@Service
@Transactional(rollbackFor = Exception.class)
public class SaCustMainService {

    public SaCustMain findOne(String id) {

        return custMapper.selectById(id);
    }

    public String insert(SaCustMain cust) {
        cust.setId(XstrUtil.getUUID());
        custMapper.insert(cust);
        return cust.getId();
    }

    public String update(SaCustMain cust) {
        custMapper.updateById(cust);
        return cust.getId();
    }

    public int delete(String[] ids) {
        for (String id : ids) {
            custMapper.deleteById(id);
        }
        return ids.length;
    }

    public void test() {
        //先通过JPA新增一个代理商
        SaAgentMain agentMain=new SaAgentMain();
        agentMain.setId(XstrUtil.getUUID());
        agentMain.setName("有事务的项目");
        agentRepo.save(agentMain);

        //再通过mybatis-plus新增一个项目，并让它报错
        SaCustMain sdCustMain=new SaCustMain();
        sdCustMain.setId(XstrUtil.getUUID()+"XXXXXXXXXXXXXXXX");//超出长度保存出错
        sdCustMain.setNotes("有事务的客户");
        custMapper.insert(sdCustMain);
    }

    @Resource
    private SaAgentMainRepo agentRepo;

    @Resource
    private SaCustMainMapper custMapper;





}

